﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace NetWorkSet
{
    public partial class Body : Form
    {
        public Body()
        {
            InitializeComponent();
        }

        private void Body_Load(object sender, EventArgs e)
        {
            this.BindListBox(0);
        }

        public void BindListBox(int index)
        {
            //清空
            this.listbSetList.Items.Clear();
            //获取XML信息
            DataSet ds = setControl1.GetXMLNameList();
            //将XML配置名绑定到LISTBOX上
            for (int i = 0; i < ds.Tables.Count; i++)
            {
                this.listbSetList.Items.Add(ds.Tables[i].Rows[0]["TEXT"].ToString());
            }
            this.listbSetList.SelectedIndex = index;
            //this.setControl1.GetXMLData(ds.Tables[0].Rows[0]["NAME"].ToString());
        }

        //清理文本框
        private void btnClear_Click(object sender, EventArgs e)
        {
            this.setControl1.btnClear();
        }

        //保存设置
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("保存之前是否应用？", "提示", MessageBoxButtons.YesNo).ToString() == "Yes")
            {
                this.setControl1.btnSubmit();//应用设置
            }
            this.setControl1.btnSave("SET1", this.listbSetList.SelectedValue.ToString());//保存设置
        }

        private void listbSetList_SelectedIndexChanged(object sender, EventArgs e)
        {
            //获取XML信息
            DataSet ds = setControl1.GetXMLNameList();
            this.setControl1.GetXMLData(ds.Tables[this.listbSetList.SelectedIndex].Rows[0]["NAME"].ToString());
        }

        //关于
        private void btnCare_Click(object sender, EventArgs e)
        {
            MessageBox.Show("怎么个事", "提示");
        }

        //获取当前选中的LIST值
        public string GetListBoxName()
        {
            return this.listbSetList.SelectedItem == null ? "" : this.listbSetList.SelectedItem.ToString();
        }

        //获取当前选中的LIST的行号
        public int GetListBoxIndex()
        {
            return this.listbSetList.SelectedIndex;
        }

        //检测当前ListBox是否选中
        public bool CheckListBox()
        {
            if (this.listbSetList.SelectedItems.Count < 1)
                return true;
            else
                return false;
        }

        //ListBox下边的修改按钮
        private void btnModify_Click(object sender, EventArgs e)
        {
            //判断列表中是否有值为选中状态
            if (this.CheckListBox())
            {
                MessageBox.Show("请选中一个要修改的配置项！", "提示");
                return;
            }
            int selectNum = GetListBoxIndex();//把列表选定的行号取出来暂时保存
            GaiMing gm = new GaiMing(GetListBoxName(),"修改配置名称",1);
            gm.ShowDialog();
            BindListBox(selectNum);//重新绑定列表，将行号还原选中
        }

        //新增配置
        private void btnAdd_Click(object sender, EventArgs e)
        {
            GaiMing gm = new GaiMing(GetListBoxName(),"新增配置",2);
            gm.ShowDialog();
        }

        //删除配置
        private void btnDel_Click(object sender, EventArgs e)
        {

        }

        ////关于
        //private void btnCare_Click(object sender, EventArgs e)
        //{
        //    this.panelControl1.btnCare();
        //}

        ////应用设置
        //private void btnSubmit_Click(object sender, EventArgs e)
        //{
        //    this.panelControl1.btnSubmit();//应用设置
        //    this.panelControl1.btnSave();//保存设置
        //}

        ////刷新按钮
        //private void btnReGet_Click(object sender, EventArgs e)
        //{
        //    this.DataLoad();
        //}

        ////刷新方法
        //public void DataLoad()
        //{
        //    this.SET1.Text = this.setControl1.GetXMLData("SET1");//调用
        //}

        ////获取当前TAB的TEXT值
        //public string GetTabTEXT()
        //{
        //    return this.panelControl1.GetTabTEXT();
        //}

        ////获取当前TAB的TEXT值
        //public string GetTabName()
        //{
        //    return this.panelControl1.GetTabName();
        //}

        ////修改当前TAB的TEXT值
        //public string SetTabName(string TabName)
        //{
        //    return this.panelControl1.SetTabName(TabName);
        //}

        //public void SetLab(int index)
        //{
        //    this.label1.Text = "SET" + (index + 1).ToString();
        //}

        //public string GetLab()
        //{
        //    return label1.Text;
        //}
    }
}
